<template>
  <Button
    :text="text"
    :type="type"
    :label="label"
    icon="pi pi-trash"
    @click="clickHandler"
  />
</template>
<script>
import { useConfirm } from 'primevue/useconfirm'

export default {
  name: 'DeleteButton',
  emits: ['confirm'],
  props: {
    text: {
      type: Boolean,
      default: true,
    },
    type: {
      type: String,
      default: '',
    },
    label: {
      type: String,
      default: '删除',
    },
    message: {
      type: String,
      default: () => {
        return '是否确认删除该数据'
      },
    },
  },
  data() {
    return {
      confirm: useConfirm(),
    }
  },
  methods: {
    clickHandler() {
      this.confirm.require({
        message: this.message,
        header: '提示',
        icon: 'pi pi-exclamation-triangle',
        rejectProps: {
          label: '取消',
          severity: 'secondary',
        },
        acceptProps: {
          label: '确定',
        },
        accept: (a) => {
          this.$emit('confirm')
        },
      })
    },
  },
}
</script>
